package com.meilai.project.mapper.media;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.meilai.project.entity.media.MediaPointChooseDaterangeComboCount;
import com.meilai.project.entity.media.MediaSpecPriceCountPO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xchen
 * @since 2022-03-13
 */
@Mapper
public interface MediaPointChooseDaterangeComboCountMapper extends BaseMapper<MediaPointChooseDaterangeComboCount> {
	@Delete("delete from media_point_choose_daterange_combo_count where choose_id = #{choose_id}")
	int deleteByChooseId(@Param("choose_id") Long chooseId);

	@Select("select * from media_point_choose_daterange_combo_count where choose_id = #{choose_id} ")
	List<MediaPointChooseDaterangeComboCount> listByChooseId(@Param("choose_id") Long chooseId);

	@Select("select  mpcdm.media_type_spec_price_id, vmtsp.`media_type_spec_name` as media_type_spec_price_name," +
			" count(*) as spec_count, mp.size_width, mp.size_height  " +
			"from media_point_choose_daterange_mediapoint mpcdm " +
			"join media_point mp on mpcdm.media_point_id = mp.id " +
			"join v_media_type_spec_price vmtsp on vmtsp.id = mpcdm.media_type_spec_price_id " +
			"where mpcdm.daterange_id = #{daterange_id} " +
			"GROUP BY mpcdm.media_type_spec_price_id ")
	List<MediaSpecPriceCountPO> mediaTypeCount(@Param("daterange_id") Long daterange_id);

	List<MediaSpecPriceCountPO> mediaTypeCountByIds(@Param("daterange_ids") List<Long> daterange_ids);

	@Select("select mpcdcc.combo_id as id, gsc.`name`,sum(mpcdcc.`count`) as `spec_count` " +
			"from media_point_choose_daterange_combo_count mpcdcc " +
			"join gas_station_combo gsc on mpcdcc.combo_id = gsc.id " +
			"where mpcdcc.daterange_id = #{daterange_id} " +
			"GROUP BY mpcdcc.combo_id ")
	List<MediaSpecPriceCountPO> comboCount(@Param("daterange_id") Long daterange_id);

	@Insert("insert into media_point_choose_daterange_combo_count" +
			"(choose_id,daterange_id,building_area_id,combo_id,rule_id,count ) " +
			"(select #{new_choose_id},#{new_daterange_id},building_area_id,combo_id,rule_id,count from media_point_choose_daterange_combo_count " +
			"where choose_id = #{old_choose_id} and daterange_id = #{old_daterange_id}) ")
	int copyOldToNew(@Param("new_choose_id") Long new_choose_id, @Param("new_daterange_id") Long new_daterange_id,
	                 @Param("old_choose_id") Long old_choose_id, @Param("old_daterange_id") Long old_daterange_id);
}
